package com.qfedu.service.impl;

import com.qfedu.dao.IProductDao;
import com.qfedu.dao.impl.ProductDaoImpl;
import com.qfedu.entity.PageBean;
import com.qfedu.entity.Product;
import com.qfedu.service.IProductService;

import java.util.List;

public class ProductService implements IProductService {
    private IProductDao productDao = new ProductDaoImpl();
    @Override
    public PageBean getPageBean(long currentPage,Integer typeid) {
        PageBean pageBean = new PageBean();
        Long allSize = productDao.getAllSize(typeid);
        pageBean.setAllSize(allSize);
        long pageSize = 3;
        pageBean.setPageSize(pageSize);
        long allPageSize = allSize%pageSize==0?allSize/pageSize:allSize/pageSize+1;
        pageBean.setAllPageSize(allPageSize);
        pageBean.setCurrentPage(currentPage);
        long begin = (currentPage-1)*pageSize;
        List<Product> productDate = productDao.listProduct(typeid,begin, pageSize);
        pageBean.setPageDate(productDate);
        return pageBean;
    }

    @Override
    public Product getProduct(long id) {
        return productDao.getProduct(id);
    }
}
